import * as vscode from 'vscode';
import { SnippetManager } from '../managers/SnippetManager';
import { Snippet } from '../types/snippet';

export class SnippetTreeProvider implements vscode.TreeDataProvider<Snippet> {
  private _onDidChangeTreeData = new vscode.EventEmitter<void>();
  readonly onDidChangeTreeData = this._onDidChangeTreeData.event;

  constructor(private snippetManager: SnippetManager) {}

  refresh(): void {
    this._onDidChangeTreeData.fire();
  }

  getTreeItem(element: Snippet): vscode.TreeItem {
    return {
      label: element.name,
      collapsibleState: vscode.TreeItemCollapsibleState.None,
      contextValue: element.isSystem ? 'systemSnippet' : 'customSnippet',
      iconPath: new vscode.ThemeIcon('symbol-snippet')
    };
  }

 async getChildren(): Promise<Snippet[]> {
  const snippets = this.snippetManager.getSnippets() as Snippet[]; // 类型断言
  return snippets.filter((s: Snippet) => !s.isSystem); // 显式类型声明
}
}
